package cmd

import (
	"fmt"
	"strings"

	"math-clc/enum"
	"math-clc/tool"

	"github.com/spf13/cobra"
)

var multiplyCmd = &cobra.Command{
	Use:   "multiply",
	Short: "Multiply subcommand multiply all passed args.",

	Run: func(cmd *cobra.Command, args []string) {
		values := tool.ConvertArgsToFloat64Slice(args, enum.ErrorHandling(parseHandling))
		result := values[0]
		for i := 1; i < len(values); i++ {
			result *= values[i]
		}
		fmt.Printf("%s = %.2f\n", strings.Join(args, "*"), result)
	},
}

func init() {
	rootCmd.AddCommand(multiplyCmd)
}
